import {http,baseURL} from "../plugin/axios.js";
import {LoginType} from "../enums/LoginTypeEnum.js";
import {userStore} from "../store/userState.js";

const loginURL = "/user/public/login"

const getUserInfoURL = "/user/auth/user_info"

const updateUserInfoURL = "/user/auth/update"


export const userLoginByPassword = (account, password) => {
    return http({
        method: 'post',
        url: baseURL+loginURL,
        data: JSON.stringify({
            loginType: LoginType.PASSWORD_LOGIN,
            account: account,
            password: password
        })
    })
}

export const userLoginByPhoneCode = (phone, code) => {
    return http({
        method: 'post',
        url: baseURL+loginURL,
        data: JSON.stringify({
            loginType: LoginType.PHONE_LOGIN,
            phone:phone,
            code:code
        })
    })
}

export const getCurrentUserInfo = ()=>{
    return http({
        method:'get',
        url:baseURL+getUserInfoURL,
        headers:{
            "Authorization":userStore().getToken()
        }
    })
}

export const updateUserInfo = (data) => {
    return http({
        method: 'POST',
        url: baseURL+updateUserInfoURL,
        header: {
            'Authorization': userStore().getToken()
        },
        data,
    })
}
